package com.luli.dao;

import com.luli.pojo.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 陆离
 * 2024/10/11 15:07:03
 */

public class UserDaoImpl implements UserMapper {

    //sqlSession不用我们自己创建了，Spring来管理
    private SqlSessionTemplate sqlSession;

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }

    public List<User> selectUser() {
        User user = new User(4,"小明","123456");
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        /**
         * 测试事务放开注释
         */
//        mapper.addUser(user);
//        mapper.deleteUser(4);
        return mapper.selectUser();
    }

    public int addUser(User user) {
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        return mapper.addUser(user);
    }

    public int deleteUser(int id) {
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        return mapper.deleteUser(id);
    }
}
